home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 176-200 / disk_195 / microemacs / src.zoo / estruct.h < prev    next >
C/C++ Source or Header  |  1989-03-23  |  25KB  |  823 lines

  1. /*    ESTRUCT:    Structure and preprocesser defined for
  2.             MicroEMACS 3.10
  3.  
  4.             written by Daniel Lawrence
  5.             based on code by Dave G. Conroy,
  6.                 Steve Wilhite and George Jones
  7. */
  8.  
  9. #ifdef    LATTICE
  10. #undef    LATTICE      /* don't use their definitions...use ours     */
  11. #endif
  12. #ifdef    MSDOS
  13. #undef    MSDOS
  14. #endif
  15. #ifdef    AMIGA
  16. #undef    AMIGA
  17. #endif
  18. #ifdef    EGA
  19. #undef    EGA
  20. #endif
  21. #ifdef    CTRLZ
  22. #undef    CTRLZ
  23. #endif
  24.  
  25. /*    Program Identification.....
  26.  
  27.     PROGNAME should always be MicroEMACS for a distribution
  28.     unmodified version. People using MicroEMACS as a shell
  29.     for other products should change this to reflect their
  30.     product. Macros can query this via the $progname variable
  31. */
  32.  
  33. #define PROGNAME    "MicroEMACS"
  34. #define    VERSION        "3.10"
  35.  
  36.  
  37. /*    Machine/OS definitions            */
  38. /*    [Set one of these!!]            */
  39.  
  40. #define AMIGA    1            /* AmigaDOS            */
  41. #define ST520    0            /* ST520, TOS            */
  42. #define MSDOS    0            /* MS-DOS            */
  43. #define OS2    0            /* Microsoft or IBM OS/2    */
  44. #define V7    0            /* V7 UNIX or Coherent or BSD4.2*/ 
  45. #define BSD    0            /* UNIX BSD 4.2 and ULTRIX    */
  46. #define USG    0            /* UNIX system V        */
  47. #define    XENIX    0            /* IBM-PC SCO XENIX        */
  48. #define    SUN    0            /* SUN v4.0            */
  49. #define    HPUX    0            /* HPUX HP 9000 minicomputer    */
  50. #define VMS    0            /* VAX/VMS            */
  51. #define FINDER    0            /* Macintosh OS         */
  52. #define WMCS    0            /* Wicat's MCS            */
  53. #define    AOSVS    0            /* Data General AOS/VS        */
  54.  
  55. /*    Compiler definitions            */
  56. /*    [Set one of these!!]            */
  57. #define UNIX    0    /* a random UNIX compiler */
  58. #define MWC    0    /* Mark Williams C */
  59. #define    ALCYON    0    /* ALCYON Atari ST compiler */ 
  60. #define LATTICE 0    /* Lattice 2.14 through 3.0 compilers */
  61. #define AZTEC    1    /* Aztec C 3.20e */
  62. #define MSC    0    /* MicroSoft C compile version 3 & 4 & 5.1 */
  63. #define TURBO    0    /* Turbo C/MSDOS */
  64. #define DTL    0    /* DataLight C v3.12 */
  65. #define    DGC    0    /* Data General AOS/VS C... */
  66.  
  67. /*      Machine stack growth direction.                     */
  68. /*  [Set this to 1 if your machine stack grows UP!!!]       */
  69. /*      data general mv/eclipse series stack grows up.      */
  70. /*      dec vax series stack grows down... got it???        */
  71.  
  72. #define STACK_GROWS_UP  0
  73.  
  74. /*    Debugging options    */
  75. #define    RAMSIZE    0    /* dynamic RAM memory usage tracking */
  76. #define    RAMSHOW    0    /* auto dynamic RAM reporting */
  77. #define    RAMTRCK    0    /* send debug info to MALLOC.DAT */
  78.  
  79. /*   Special keyboard/network definitions         */
  80.  
  81. #define WANGPC    0        /* WangPC - mostly escape sequences    */
  82. #define VT100    0        /* Handle VT100 style keypad.    */
  83. #define XONDATA    0        /* VMS only - set to force /NOTTSYNC/NOHOSTSY */
  84. #define    NOVELL    0        /* IBMPC Novell NetWare flag! */
  85.  
  86. /*    Terminal Output definitions        */
  87. /*    [Set one of these!!]            */
  88.  
  89. #define ANSI    1            /* ANSI escape sequences    */
  90. #define    HP150    0            /* HP150 screen driver        */
  91. #define    HP110    0            /* HP110 screen driver        */
  92. #define    VMSVT    0            /* various VMS terminal entries    */
  93. #define VT52    0            /* VT52 terminal (Zenith).    */
  94. #define RAINBOW 0            /* Use Rainbow fast video.    */
  95. #define TERMCAP 0            /* Use TERMCAP            */
  96. #define    IBMPC    0            /* IBM-PC CGA/MONO/EGA/VGA drvr    */
  97. #define OS2NPM    0            /* OS/2 non-Presentation Mgr.    */
  98. #define    DG10    0            /* Data General system/10    */
  99. #define    TIPC    0            /* TI Profesional PC driver    */
  100. #define    Z309    0            /* Zenith 100 PC family    driver    */
  101. #define    MAC    0            /* Macintosh            */
  102. #define    ATARI    0            /* Atari 520/1040ST screen    */
  103. #define    DASHER    0            /* DG Dasher 2xx/4xx crts    */
  104.  
  105. /*    Language text options    (pick one)                */
  106.  
  107. #define ENGLISH 1
  108. #define    FRENCH    0
  109. #define    SPANISH    0
  110. #define    GERMAN    0
  111. #define    DUTCH    0
  112. #define PLATIN    0
  113.  
  114. /*    Configuration options    */
  115.  
  116. #define CVMVAS    1    /* arguments to page forward/back in pages    */
  117. #define    CLRMSG    0    /* space clears the message line with no insert    */
  118. #define    CFENCE    1    /* fench matching in CMODE            */
  119. #define    TYPEAH    1    /* type ahead causes update to be skipped    */
  120. #define DEBUGM    1    /* $debug triggers macro debugging        */
  121. #define    LOGFLG    0    /* send all executed commands to EMACS.LOG    */
  122. #define    VISMAC    0    /* update display during keyboard macros    */
  123. #define    CTRLZ    0    /* add a ^Z at end of files under MSDOS only    */
  124. #define    NBRACE    1    /* new style brace matching command        */
  125. #define    COMPLET    1    /* new completion code (as of 3.10)        */
  126. #define    CLEAN    0    /* de-alloc memory on exit            */
  127. #define    CALLED    0    /* is emacs a called subroutine? or stand alone */
  128. #define ADDCR    0    /* ajout d'un CR en fin de chaque ligne (ST520) */
  129.             /* [= add a CR at the end of each line (ST520)] */
  130. #define    BINARY    1    /* using new binary searches?            */
  131.  
  132. #define REVSTA    1    /* Status line appears in reverse video     */
  133. #define    COLOR    1    /* color commands and windows            */
  134.  
  135. #define FILOCK    0    /* file locking under unix BSD 4.2        */
  136. #define    ISRCH    1    /* Incremental searches like ITS EMACS        */
  137. #define    WORDPRO    1    /* Advanced word processing features        */
  138. #define    FLABEL    0    /* function key label code [HP150]        */
  139. #define    APROP    1    /* Add code for Apropos command            */
  140. #define    CRYPT    1    /* file encryption enabled?            */
  141. #define MAGIC    1    /* include regular expression matching?        */
  142. #define    AEDIT    1    /* advanced editing options: en/detabbing    */
  143. #define    PROC    1    /* named procedures                */
  144. #define MOUSE    1    /* Include routines for mouse actions        */
  145. #define    NOISY    1    /* Use a fancy BELL if it exists        */
  146. #define    DIACRIT    1    /* diacritical marks processed?            */
  147. #define    SPEECH    0    /* spoken EMACS, for the sight impared [not ready] */
  148.  
  149. /*    Character set options        */
  150. /*    [Set one of these!!]        */
  151. #define ASCII    1    /* always using ASCII char sequences for now    */
  152. #define EBCDIC    0    /* later IBM mainfraim versions will use EBCDIC    */
  153.  
  154. /* handle constant and voids properly */
  155.  
  156. #if    VMS
  157. #define    CONST    readonly
  158. #define    VOID    void
  159. #define NOSHARE noshare
  160. #else
  161. #if    AOSVS
  162. #define CONST $shared $align(1)     /* fake a  const */
  163. #define    VOID
  164. #define NOSHARE $low32k $align(1)   /* attempt to optimize read/write vars. */
  165. #else
  166. #ifdef    __STDC__
  167. #define    CONST    const
  168. #define    VOID    void
  169. #define    NOSHARE
  170. #else
  171. #define    CONST
  172. #define    VOID
  173. #define NOSHARE
  174. #endif
  175. #endif
  176. #endif
  177.  
  178. /*    System dependant library redefinitions, structures and includes */
  179.  
  180. /*    the following define allows me to initialize unions...
  181.     otherwise we make them structures (like the keybinding table)  */
  182.  
  183. #if    __STDC__    /* if ANSI C compatible */
  184. #define    ETYPE    union
  185. #else
  186. #define    ETYPE    struct
  187. #endif
  188.  
  189. #if MSDOS & (TURBO | MSC)
  190. #define    NEAR
  191. #define    DNEAR
  192. #define    PASCAL pascal
  193. #define    CDECL cdecl
  194. #else
  195. #define NEAR
  196. #define    DNEAR
  197. #define    PASCAL
  198. #define    CDECL
  199. #endif
  200.  
  201. #if    TURBO
  202. #include      <dos.h>
  203. #include      <mem.h>
  204. #undef peek
  205. #undef poke
  206. #define       peek(a,b,c,d)   movedata(a,b,FP_SEG(c),FP_OFF(c),d)
  207. #define       poke(a,b,c,d)   movedata(FP_SEG(c),FP_OFF(c),a,b,d)
  208. #endif
  209.  
  210. #if    LATTICE & MSDOS
  211. /* you may have to remove this one definition with LATTICE version
  212.    3.2 and above                          */
  213. #define    unsigned
  214. #endif
  215.  
  216. #if    AZTEC
  217. #undef    putc
  218. #undef    getc
  219. #if    MSDOS
  220. #define    getc    a1getc
  221. #define    int86    sysint
  222. #define    intdos(a, b)    sysint(33, a, b)
  223. #define    inp    inportb
  224. #define    outp    outportb
  225. #else
  226. #define getc    agetc
  227. #endif
  228. #define putc    aputc
  229.  
  230. struct XREG {
  231.     unsigned ax,bx,cx,dx,si,di,ds,es;
  232. };
  233.  
  234. struct HREG {
  235.     char al,ah,bl,bh,cl,ch,dl,dh,d1,d2,e1,e2;
  236. };
  237.  
  238. union REGS {
  239.     struct XREG x;
  240.     struct HREG h;
  241. };
  242.  
  243. struct SREGS {
  244.     unsigned cs, ss, ds, es;
  245. };
  246. #endif
  247.  
  248. #if    MSDOS & DTL
  249. #include    <dos.h>
  250. #endif
  251.  
  252. #if    MSDOS & MWC
  253. #include    <dos.h>
  254. #define    int86(a, b, c)    intcall(b, c, a)
  255. #define    intdos(a, b)    intcall(a, b, DOSINT)
  256. #define    inp(a)        in(a)
  257. #define    outp(a, b)    out(a, b)
  258. #define    movmem(a, b, c)    memcpy(b, a, c)
  259.  
  260. struct XREG {
  261.     unsigned int ax,bx,cx,dx,si,di,ds,es,flags;
  262. };
  263.  
  264. struct HREG {
  265.     char al,ah,bl,bh,cl,ch,dl,dh;
  266.     unsigned int ds,es,flags;
  267. };
  268.  
  269. union REGS {
  270.     struct XREG x;
  271.     struct HREG h;
  272. };
  273. #endif
  274.  
  275. #if    MSDOS & MSC
  276. #include    <dos.h>
  277. #include    <memory.h>
  278. #define    peek(a,b,c,d)    movedata(a,b,FP_SEG(c),FP_OFF(c),d)
  279. #define    poke(a,b,c,d)    movedata(FP_SEG(c),FP_OFF(c),a,b,d)
  280. #define    movmem(a, b, c)        memcpy(b, a, c)
  281. #endif
  282.  
  283. #if    MSDOS & LATTICE
  284. #undef    CPM
  285. #undef    LATTICE
  286. #include    <dos.h>
  287. #undef    CPM
  288. #endif
  289.  
  290. /* this keeps VMS happy */
  291. #if    VMS
  292. #define    getname xgetname
  293. #define    unlink(a)    delete(a)
  294. #endif
  295.  
  296. /* some options for AOS/VS */
  297. #if     AOSVS
  298. #define ORMDNI  1
  299. #endif
  300.  
  301. /*    define some ability flags */
  302.  
  303. #if    IBMPC | Z309
  304. #define    MEMMAP    1
  305. #else
  306. #define MEMMAP    0
  307. #endif
  308.  
  309. #if    MSDOS | OS2 | V7 | USG | HPUX | BSD | (ST520 & MWC) | WMCS
  310. #define    ENVFUNC    1
  311. #else
  312. #define ENVFUNC 0
  313. #endif
  314.  
  315. #if    ATARI || MSDOS || OS2
  316. #define    DIRSEPSTR    "\\"
  317. #define    DIRSEPCHAR    '\\'
  318. #else
  319. #define DIRSEPSTR    "/"
  320. #define    DIRSEPCHAR    '/'
  321. #endif
  322.  
  323. /*    Emacs global flag bit definitions (for gflags)    */
  324.  
  325. #define GFREAD    1
  326.  
  327. /*    internal constants    */
  328.  
  329. #define NBINDS    300            /* max # of bound keys        */
  330. #if    AOSVS == 0
  331. #define NFILEN    80            /* # of bytes, file name    */
  332. #else
  333. #define    NFILEN    256
  334. #endif
  335. #define NBUFN    32            /* # of bytes, buffer name    */
  336. #define NLINE    256            /* # of bytes, input line    */
  337. #define    NSTRING    128            /* # of bytes, string buffers    */
  338. #define NKBDM    256            /* # of strokes, keyboard macro */
  339. #define NPAT    128            /* # of bytes, pattern        */
  340. #define HUGE    1000            /* Huge number            */
  341. #define    NLOCKS    100            /* max # of file locks active    */
  342. #define    NCOLORS    16            /* number of supported colors    */
  343. #define    KBLOCK    250            /* sizeof kill buffer chunks    */
  344. #define    NBLOCK    16            /* line block chunk size    */
  345. #define    NVSIZE    10            /* max #chars in a var name    */
  346. #define NMARKS    10            /* number of marks        */
  347.  
  348. #define CTRL    0x0100        /* Control flag, or'ed in        */
  349. #define META    0x0200        /* Meta flag, or'ed in            */
  350. #define CTLX    0x0400        /* ^X flag, or'ed in            */
  351. #define SPEC    0x0800        /* special key (function keys)        */
  352. #define MOUS    0x1000        /* alternative input device (mouse)    */
  353. #define    SHFT    0x2000        /* shifted (for function keys)        */
  354. #define    ALTD    0x4000        /* ALT key...                */
  355.  
  356. #define    BINDNUL    0        /* not bount to anything        */
  357. #define    BINDFNC    1        /* key bound to a function        */
  358. #define    BINDBUF    2        /* key bound to a buffer        */
  359.  
  360. #ifdef    FALSE
  361. #undef    FALSE
  362. #endif
  363. #ifdef    TRUE
  364. #undef    TRUE
  365. #endif
  366.  
  367. #define FALSE    0            /* False, no, bad, etc.     */
  368. #define TRUE    1            /* True, yes, good, etc.    */
  369. #define ABORT    2            /* Death, ^G, abort, etc.    */
  370. #define    FAILED    3            /* not-quite fatal false return    */
  371.  
  372. #define STOP    0            /* keyboard macro not in use    */
  373. #define    PLAY    1            /*          playing    */
  374. #define    RECORD    2            /*          recording    */
  375.  
  376. /*    Competion types        */
  377.  
  378. #define    CMP_BUFFER    0
  379. #define    CMP_COMMAND    1
  380. #define    CMP_FILENAME    2
  381.  
  382. /*    Directive definitions    */
  383.  
  384. #define DIF        0
  385. #define DELSE        1
  386. #define DENDIF        2
  387. #define DGOTO        3
  388. #define DRETURN        4
  389. #define DENDM        5
  390. #define DWHILE        6
  391. #define    DENDWHILE    7
  392. #define    DBREAK        8
  393. #define DFORCE        9
  394.  
  395. #define NUMDIRS     10
  396.  
  397. /*
  398.  * PTBEG, PTEND, FORWARD, and REVERSE are all toggle-able values for
  399.  * the scan routines.
  400.  */
  401. #define PTBEG    0    /* Leave the point at the beginning on search    */
  402. #define    PTEND    1    /* Leave the point at the end on search        */
  403. #define    FORWARD    0            /* forward direction        */
  404. #define REVERSE    1            /* backwards direction        */
  405.  
  406. #define FIOSUC    0            /* File I/O, success.        */
  407. #define FIOFNF    1            /* File I/O, file not found.    */
  408. #define FIOEOF    2            /* File I/O, end of file.    */
  409. #define FIOERR    3            /* File I/O, error.        */
  410. #define    FIOMEM    4            /* File I/O, out of memory    */
  411. #define    FIOFUN    5            /* File I/O, eod of file/bad line*/
  412. #define    FIODEL    6            /* Can't delete/rename file    */
  413.  
  414. #define CFCPCN    0x0001            /* Last command was C-P, C-N    */
  415. #define CFKILL    0x0002            /* Last command was a kill    */
  416.  
  417. #define BELL    0x07            /* a bell character        */
  418. #define    TAB    0x09            /* a tab character        */
  419.  
  420. #if    V7 | USG | HPUX | BSD
  421. #define    PATHCHR    ':'
  422. #else
  423. #if    WMCS
  424. #define    PATHCHR ','
  425. #else
  426. #define PATHCHR ';'
  427. #endif
  428. #endif
  429.  
  430. #define INTWIDTH    sizeof(int) * 3
  431.  
  432. /*    Macro argument token types                    */
  433.  
  434. #define TKNUL    0            /* end-of-string        */
  435. #define    TKARG    1            /* interactive argument        */
  436. #define    TKBUF    2            /* buffer argument        */
  437. #define    TKVAR    3            /* user variables        */
  438. #define    TKENV    4            /* environment variables    */
  439. #define    TKFUN    5            /* function....            */
  440. #define    TKDIR    6            /* directive            */
  441. #define    TKLBL    7            /* line label            */
  442. #define    TKLIT    8            /* numeric literal        */
  443. #define    TKSTR    9            /* quoted string literal    */
  444. #define    TKCMD    10            /* command name            */
  445.  
  446. /*    Internal defined functions                    */
  447.  
  448. #define nextab(a)    (a - (a % tabsize)) + tabsize
  449.  
  450. /* DIFCASE represents the integer difference between upper
  451.    and lower case letters.  It is an xor-able value, which is
  452.    fortunate, since the relative positions of upper to lower
  453.    case letters is the opposite of ascii in ebcdic.
  454. */
  455.  
  456. #ifdef    islower
  457. #undef    islower
  458. #endif
  459. #ifdef    isupper
  460. #undef    isupper
  461. #endif
  462.  
  463. #if    ASCII
  464. #define    DIFCASE     0x20
  465. #if    DIACRIT == 0
  466. #define isletter(c)    (('a' <= c && 'z' >= c) || ('A' <= c && 'Z' >= c))
  467. #define islower(c)    (('a' <= c && 'z' >= c))
  468. #define isupper(c)    (('A' <= c && 'Z' >= c))
  469. #endif
  470. #endif
  471.  
  472. #if    EBCDIC
  473. #define    DIFCASE     0x40
  474. #define isletter(c)    (('a' <= c && 'i' >= c) || ('j' <= c && 'r' >= c) || ('s' <= c && 'z' >= c) || ('A' <= c && 'I' >= c) || ('J' <= c && 'R' >= c) || ('S' <= c && 'Z' >= c))
  475. #define islower(c)    (('a' <= c && 'i' >= c) || ('j' <= c && 'r' >= c) || ('s' <= c && 'z' >= c))
  476. #define isupper(c)    (('A' <= c && 'I' >= c) || ('J' <= c && 'R' >= c) || ('S' <= c && 'Z' >= c))
  477. #endif
  478.  
  479. #if    DIACRIT
  480. #define    CHCASE(c)    chcase(c)    /* Toggle extended letter case.*/
  481. #else
  482. #define CHCASE(c)    ((c) ^ DIFCASE) /* Toggle the case of a letter.*/
  483. #endif
  484.  
  485. /*    Dynamic RAM tracking and reporting redefinitions    */
  486.  
  487. #if    RAMSIZE
  488. #define    malloc    allocate
  489. #define    free    release
  490. #endif
  491.  
  492.  
  493. /*
  494.  * There is a window structure allocated for every active display window. The
  495.  * windows are kept in a big list, in top to bottom screen order, with the
  496.  * listhead at "wheadp". Each window contains its own values of dot and mark.
  497.  * The flag field contains some bits that are set by commands to guide
  498.  * redisplay. Although this is a bit of a compromise in terms of decoupling,
  499.  * the full blown redisplay is just too expensive to run for every input
  500.  * character.
  501.  */
  502. typedef struct    WINDOW {
  503.     struct    WINDOW *w_wndp;     /* Next window            */
  504.     struct    BUFFER *w_bufp;     /* Buffer displayed in window    */
  505.     struct    LINE *w_linep;        /* Top line in the window    */
  506.     struct    LINE *w_dotp;        /* Line containing "."        */
  507.     short    w_doto;         /* Byte offset for "."        */
  508.     struct    LINE *w_markp[NMARKS];    /* Line containing "mark"    */
  509.     short    w_marko[NMARKS];    /* Byte offset for "mark"    */
  510.     char    w_toprow;        /* Origin 0 top row of window    */
  511.     char    w_ntrows;        /* # of rows of text in window    */
  512.     char    w_force;        /* If NZ, forcing row.        */
  513.     char    w_flag;         /* Flags.            */
  514. #if    COLOR
  515.     char   w_fcolor;           /* current forground color      */
  516.     char    w_bcolor;        /* current background color    */
  517. #endif
  518.     int    w_fcol;         /* first column displayed    */
  519. }    WINDOW;
  520.  
  521. #define WFFORCE 0x01            /* Window needs forced reframe    */
  522. #define WFMOVE    0x02            /* Movement from line to line    */
  523. #define WFEDIT    0x04            /* Editing within a line    */
  524. #define WFHARD    0x08            /* Better to a full display    */
  525. #define WFMODE    0x10            /* Update mode line.        */
  526. #define    WFCOLR    0x20            /* Needs a color change        */
  527.  
  528. /*
  529.  * Text is kept in buffers. A buffer header, described below, exists for every
  530.  * buffer in the system. The buffers are kept in a big list, so that commands
  531.  * that search for a buffer by name can find the buffer header. There is a
  532.  * safe store for the dot and mark in the header, but this is only valid if
  533.  * the buffer is not being displayed (that is, if "b_nwnd" is 0). The text for
  534.  * the buffer is kept in a circularly linked list of lines, with a pointer to
  535.  * the header line in "b_linep"    Buffers may be "Inactive" which means the files associated with them
  536.  * have not been read in yet. These get read in at "use buffer" time.
  537.  */
  538. typedef struct    BUFFER {
  539.     struct    BUFFER *b_bufp;     /* Link to next BUFFER        */
  540.     struct    LINE *b_dotp;        /* Link to "." LINE structure    */
  541.     short    b_doto;         /* Offset of "." in above LINE    */
  542.     struct    LINE *b_markp[NMARKS];    /* The same as the above two,    */
  543.     short    b_marko[NMARKS];    /* but for the "mark"        */
  544.     int    b_fcol;            /* first col to display        */
  545.     struct    LINE *b_linep;        /* Link to the header LINE    */
  546.     struct    LINE *b_topline;    /* Link to narrowed top text    */
  547.     struct    LINE *b_botline;    /* Link to narrowed bottom text    */
  548.     char    b_active;        /* window activated flag    */
  549.     char    b_nwnd;         /* Count of windows on buffer    */
  550.     char    b_flag;         /* Flags            */
  551.     int    b_mode;            /* editor mode of this buffer    */
  552.     char    b_fname[NFILEN];    /* File name            */
  553.     char    b_bname[NBUFN];     /* Buffer name            */
  554. #if    CRYPT
  555.     char   b_key[NPAT];           /* current encrypted key        */
  556. #endif
  557. }    BUFFER;
  558.  
  559. #define BFINVS    0x01            /* Internal invisable buffer    */
  560. #define BFCHG    0x02            /* Changed since last write    */
  561. #define    BFTRUNC    0x04            /* buffer was truncated when read */
  562. #define    BFNAROW    0x08            /* buffer has been narrowed    */
  563.  
  564. /*    mode flags    */
  565. #define    NUMMODES    9           /* # of defined modes           */
  566.  
  567. #define MDWRAP    0x0001            /* word wrap            */
  568. #define    MDCMOD    0x0002            /* C indentation and fence match*/
  569. #define    MDSPELL    0x0004            /* spell error parsing        */
  570. #define    MDEXACT    0x0008            /* Exact matching for searches    */
  571. #define    MDVIEW    0x0010            /* read-only buffer        */
  572. #define MDOVER    0x0020            /* overwrite mode        */
  573. #define MDMAGIC    0x0040            /* regular expresions in search */
  574. #define    MDCRYPT    0x0080            /* encrytion mode active    */
  575. #define    MDASAVE    0x0100            /* auto-save mode        */
  576.  
  577. /*
  578.  * The starting position of a region, and the size of the region in
  579.  * characters, is kept in a region structure.  Used by the region commands.
  580.  */
  581. typedef struct    {
  582.     struct    LINE *r_linep;        /* Origin LINE address.     */
  583.     short    r_offset;        /* Origin LINE offset.        */
  584.     long    r_size;         /* Length in characters.    */
  585. }    REGION;
  586.  
  587. /*
  588.  * All text is kept in circularly linked lists of "LINE" structures. These
  589.  * begin at the header line (which is the blank line beyond the end of the
  590.  * buffer). This line is pointed to by the "BUFFER". Each line contains a the
  591.  * number of bytes in the line (the "used" size), the size of the text array,
  592.  * and the text. The end of line is not stored as a byte; it's implied.
  593.  */
  594. typedef struct    LINE {
  595.     struct    LINE *l_fp;        /* Link to the next line    */
  596.     struct    LINE *l_bp;        /* Link to the previous line    */
  597.     short    l_size;         /* Allocated size        */
  598.     short    l_used;         /* Used size            */
  599.     char    l_text[1];        /* A bunch of characters.    */
  600. }    LINE;
  601.  
  602. #define lforw(lp)    ((lp)->l_fp)
  603. #define lback(lp)    ((lp)->l_bp)
  604. #define lgetc(lp, n)    ((lp)->l_text[(n)]&0xFF)
  605. #define lputc(lp, n, c) ((lp)->l_text[(n)]=(c))
  606. #define llength(lp)    ((lp)->l_used)
  607.  
  608. /*
  609.  * The editor communicates with the display using a high level interface. A
  610.  * "TERM" structure holds useful variables, and indirect pointers to routines
  611.  * that do useful operations. The low level get and put routines are here too.
  612.  * This lets a terminal, in addition to having non standard commands, have
  613.  * funny get and put character code too. The calls might get changed to
  614.  * "termp->t_field" style in the future, to make it possible to run more than
  615.  * one terminal type.
  616.  */
  617. typedef struct    {
  618.     short    t_mrow;          /* max number of rows allowable */
  619.     short    t_nrow;         /* current number of rows used    */
  620.     short    t_mcol;         /* max Number of columns.    */
  621.     short    t_ncol;         /* current Number of columns.    */
  622.     short    t_margin;        /* min margin for extended lines*/
  623.     short    t_scrsiz;        /* size of scroll region "    */
  624.     int    t_pause;        /* # times thru update to pause */
  625.     int (PASCAL NEAR *t_open)();    /* Open terminal at the start.    */
  626.     int (PASCAL NEAR *t_close)();    /* Close terminal at end.    */
  627.     int (PASCAL NEAR *t_kopen)();    /* Open keyboard        */
  628.     int (PASCAL NEAR *t_kclose)();    /* close keyboard        */
  629.     int (PASCAL NEAR *t_getchar)(); /* Get character from keyboard. */
  630.     int (PASCAL NEAR *t_putchar)(); /* Put character to display.    */
  631.     int (PASCAL NEAR *t_flush)();    /* Flush output buffers.    */
  632.     int (PASCAL NEAR *t_move)();    /* Move the cursor, origin 0.    */
  633.     int (PASCAL NEAR *t_eeol)();    /* Erase to end of line.    */
  634.     int (PASCAL NEAR *t_eeop)();    /* Erase to end of page.    */
  635.     int (PASCAL NEAR *t_beep)();    /* Beep.            */
  636.     int (PASCAL NEAR *t_rev)();    /* set reverse video state    */
  637.     int (PASCAL NEAR *t_rez)();    /* change screen resolution    */
  638. #if    COLOR
  639.     int (PASCAL NEAR *t_setfor)(); /* set forground color           */
  640.     int (PASCAL NEAR *t_setback)();    /* set background color        */
  641. #endif
  642. }    TERM;
  643.  
  644. /*    TEMPORARY macros for terminal I/O  (to be placed in a machine
  645.                         dependant place later) */
  646.  
  647. #define TTopen        (*term.t_open)
  648. #define    TTclose        (*term.t_close)
  649. #define    TTkopen        (*term.t_kopen)
  650. #define    TTkclose    (*term.t_kclose)
  651. #define    TTgetc        (*term.t_getchar)
  652. #define    TTputc        (*term.t_putchar)
  653. #define    TTflush        (*term.t_flush)
  654. #define    TTmove        (*term.t_move)
  655. #define    TTeeol        (*term.t_eeol)
  656. #define    TTeeop        (*term.t_eeop)
  657. #define    TTbeep        (*term.t_beep)
  658. #define    TTrev        (*term.t_rev)
  659. #define    TTrez        (*term.t_rez)
  660. #if    COLOR
  661. #define    TTforg        (*term.t_setfor)
  662. #define    TTbacg        (*term.t_setback)
  663. #endif
  664.  
  665. /*    Structure for the table of current key bindings     */
  666.  
  667. ETYPE EPOINTER {
  668.     int (PASCAL NEAR *fp)();    /* C routine to invoke */
  669.     BUFFER *buf;            /* buffer to execute */
  670. };
  671.  
  672. typedef struct    {
  673.     short k_code;         /* Key code            */
  674.     short k_type;        /* binding type (C function or EMACS buffer) */
  675.     ETYPE EPOINTER k_ptr;    /* ptr to thing to execute */
  676. }    KEYTAB;
  677.  
  678. /*    structure for the name binding table        */
  679.  
  680. typedef struct {
  681.     char *n_name;            /* name of function key */
  682.     int (PASCAL NEAR *n_func)();    /* function name is bound to */
  683. }    NBIND;
  684.  
  685. /*    The editor holds deleted text chunks in the KILL buffer. The
  686.     kill buffer is logically a stream of ascii characters, however
  687.     due to its unpredicatable size, it gets implemented as a linked
  688.     list of chunks. (The d_ prefix is for "deleted" text, as k_
  689.     was taken up by the keycode structure)
  690. */
  691.  
  692. typedef struct KILL {
  693.     struct KILL *d_next;   /* link to next chunk, NULL if last */
  694.     char d_chunk[KBLOCK];    /* deleted text */
  695. } KILL;
  696.  
  697. /*    When emacs' command interpetor needs to get a variable's name,
  698.     rather than it's value, it is passed back as a VDESC variable
  699.     description structure. The v_num field is a index into the
  700.     appropriate variable table.
  701. */
  702.  
  703. typedef struct VDESC {
  704.     int v_type;    /* type of variable */
  705.     int v_num;    /* ordinal pointer to variable in list */
  706. } VDESC;
  707.  
  708. /*    The !WHILE directive in the execution language needs to
  709.     stack references to pending whiles. These are stored linked
  710.     to each currently open procedure via a linked list of
  711.     the following structure
  712. */
  713.  
  714. typedef struct WHBLOCK {
  715.     LINE *w_begin;        /* ptr to !while statement */
  716.     LINE *w_end;        /* ptr to the !endwhile statement*/
  717.     int w_type;        /* block type */
  718.     struct WHBLOCK *w_next;    /* next while */
  719. } WHBLOCK;
  720.  
  721. #define BTWHILE     1
  722. #define    BTBREAK        2
  723.  
  724. /*
  725.  * Incremental search defines.
  726.  */
  727. #if    ISRCH
  728.  
  729. #define CMDBUFLEN    256    /* Length of our command buffer */
  730.  
  731. #define IS_ABORT    0x07    /* Abort the isearch */
  732. #define IS_BACKSP    0x08    /* Delete previous char */
  733. #define    IS_TAB        0x09    /* Tab character (allowed search char) */
  734. #define IS_NEWLINE    0x0D    /* New line from keyboard (Carriage return) */
  735. #define    IS_QUOTE    0x11    /* Quote next character */
  736. #define IS_REVERSE    0x12    /* Search backward */
  737. #define    IS_FORWARD    0x13    /* Search forward */
  738. #define    IS_VMSQUOTE    0x16    /* VMS quote character */
  739. #define    IS_VMSFORW    0x18    /* Search forward for VMS */
  740. #define    IS_QUIT        0x1B    /* Exit the search */
  741. #define    IS_RUBOUT    0x7F    /* Delete previous character */
  742.  
  743. /* IS_QUIT is no longer used, the variable metac is used instead */
  744.  
  745. #endif
  746.  
  747. /* HICHAR - 1 is the largest character we will deal with.
  748.  * HIBYTE represents the number of bytes in the bitmap.
  749.  */
  750. #define HICHAR        256
  751. #define    HIBYTE        HICHAR >> 3
  752.  
  753. #if    MAGIC
  754. /*
  755.  * Defines for the metacharacters in the regular expression
  756.  * search routines.
  757.  */
  758. #define MCNIL        0    /* Like the '\0' for strings.*/
  759. #define    LITCHAR        1    /* Literal character, or string.*/
  760. #define    ANY        2
  761. #define    CCL        3
  762. #define    NCCL        4
  763. #define    BOL        5
  764. #define    EOL        6
  765. #define    DITTO        7
  766. #define    CLOSURE        256    /* An or-able value.*/
  767. #define    MASKCL        CLOSURE - 1
  768.  
  769. #define MC_ANY        '.'    /* 'Any' character (except newline).*/
  770. #define    MC_CCL        '['    /* Character class.*/
  771. #define    MC_NCCL        '^'    /* Negate character class.*/
  772. #define    MC_RCCL        '-'    /* Range in character class.*/
  773. #define    MC_ECCL        ']'    /* End of character class.*/
  774. #define    MC_BOL        '^'    /* Beginning of line.*/
  775. #define    MC_EOL        '$'    /* End of line.*/
  776. #define    MC_CLOSURE    '*'    /* Closure - does not extend past newline.*/
  777. #define    MC_DITTO    '&'    /* Use matched string in replacement.*/
  778. #define    MC_ESC        '\\'    /* Escape - suppress meta-meaning.*/
  779.  
  780. #define BIT(n)        (1 << (n))    /* An integer with one bit set.*/
  781.  
  782. /* Typedefs that define the bitmap type for searching (BITMAP),
  783.  * the meta-character structure for MAGIC mode searching (MC),
  784.  * and the meta-character structure for MAGIC mode replacment (RMC).
  785.  */
  786. typedef char    *BITMAP;
  787.  
  788. typedef struct {
  789.     short int      mc_type;
  790.     union {
  791.            int     lchar;
  792.         BITMAP    cclmap;
  793.     } u;
  794. } MC;
  795.  
  796. typedef struct {
  797.     short int      mc_type;
  798.     char    *rstr;
  799. } RMC;
  800. #endif
  801.  
  802. /*
  803.     This is the message which should be added to any "About MicroEMACS"
  804.     boxes on any of the machines with window managers.
  805.  
  806.  
  807.     ------------------------------------------
  808.     |                     |
  809.     |     MicroEMACS v3.xx         |
  810.     |        for the ............     |
  811.     |                     |
  812.     |    Text Editor and Corrector         |
  813.     |                     |
  814.     |    written by Daniel M. Lawrence     |
  815.     |    [based on code by Dave Conroy]     |
  816.     |                     |
  817.     |    Send inquiries and donations to:     |
  818.     |    617 New York St             |
  819.     |    Lafayette, IN 47901         |
  820.     |                     |
  821.     ------------------------------------------
  822. */
  823.